/**
 *
 * @author 
 * 关卡数据
 */
class SkillManager extends egret.EventDispatcher {
    private static _i: SkillManager;
    public static get i(): SkillManager {
        if(!this._i)
            this._i = new SkillManager();
        return this._i;
    }
    public constructor() {
        super();
    }

    private _list: KillBase[] = [];
    public set list(value:KillBase[]) {
		this._list = value;
	}
    public get list(): KillBase[] {
		return this._list;
	}
    private enterFrameCount: number = 0;
    private hitOneCount: number = 0;
    private iceCount: number = 0;
    private objCon: egret.DisplayObjectContainer;

    private _hitOnePiceBtn: KillBase;
    private _hitOneBtn: KillBase;
    private _hitALLBtn: KillBase;
    private _iceBtn: KillBase;
    private _poisonBtn: KillBase;
    private _godBtn: KillBase;
    private _upgradeBtn: egret.Bitmap;
	
	
    public setup(obj: egret.DisplayObjectContainer): void {
        this.objCon = obj;
        this.initView();
        this.addEvent();
    }
	
    public GameReStart(): void {
		this.enterFrameCount = 0;
		this.hitOneCount = 0;
		this.iceCount = 0;
		this.objCon.removeChildren();
        this.removeEvent();
        this.initView();
        this.addEvent();
    }
	
    public enterFrame(): void {
		this.iceEnterFrame();

        for (var i: number = 0; i < this._list.length; i++) {
            this._list[i].enterFrame();
		}
        this.enterFrameCount++;
    }
	
    private iceEnterFrame(): void {
        if(this.iceCount != 0 && this.enterFrameCount - this.iceCount > this._iceBtn.data.durationTime) {
            if(EnemyManage.i.allStopflg) {
                EnemyManage.i.allStopflg = false;
                for(var i in EnemyManage.i.armyList) {
                    var armyTemp = EnemyManage.i.armyList[i];
                    armyTemp.play();
                }
            }
        }
    }
    private shape: egret.Sprite = new egret.Sprite();
    private initView(): void {
//        this._hitOnePiceBtn = new KillBase("kill_07");
//        this._hitOnePiceBtn.data = new HitOneInfo();
//		this._list.push(this._hitOnePiceBtn);
		
        this._hitOneBtn = new KillBase("kill_07");
        this._hitOneBtn.data = new HitOneInfo();
		this._list.push(this._hitOneBtn);
		
        this._hitALLBtn = new KillBase("kill_08");
        this._hitALLBtn.data = new HitALLInfo();
		this._list.push(this._hitALLBtn);
		
        this._iceBtn = new KillBase("kill_04");
        this._iceBtn.data = new IceInfo();
		this._list.push(this._iceBtn);
		
//        this._poisonBtn = new KillBase("kill_15");
//        this._hitOnePiceBtn.data = new PoisonInfo();
//		this._list.push(this._poisonBtn);
		
//        this._godBtn = new KillBase("kill_30");
//        this._hitOnePiceBtn.data = new GodInfo();
//		this._list.push(this._godBtn);

		for(var i in this._list) {
			if(this._list[i] == this._hitOneBtn){
				this._hitOneBtn.x = -100;
				this._hitOneBtn.visible = false;
			}else{
				this._list[i].x = 10 + 95 * (i-1);
				this._list[i].y = 608;
			}
            this.objCon.addChild(this._list[i]);
		}
		
        this._upgradeBtn = CreateObject.createBitmapByName("menueBtn", true);
        this._upgradeBtn.x = 430;
        this._upgradeBtn.y = 618;
		this.objCon.addChild(this._upgradeBtn);
    }
    private TOUCH_TAP_Handle(e: egret.TouchEvent): void {
        if(e.target == this._hitOnePiceBtn) {
            this.hitOnePice();
        } else if(e.target == this._hitALLBtn) {
            if(this._hitALLBtn.data.times == 0) {
                this._hitALLBtn.data.times = this._hitALLBtn.data.hitDelayTime;
                this.hitAll();
            }
        } else if(e.target == this._iceBtn) {
            if(this._iceBtn.data.times == 0) {
                this._iceBtn.data.times = this._iceBtn.data.hitDelayTime;
                this.iceAll();
            }
        } else if(e.target == this._poisonBtn) {
            this.poisonAll();
        } else if(e.target == this._godBtn) {
            this.god();
        } else if(e.target == this._upgradeBtn) {
			GameManager.i.GamePause();
			Global.dispatchEvent(MainNotify.openUpgradePanelNotify);
        }
    }

    private hitOnePice(): void {

    }
        
    public hitOne(armyTemp:ArmyBase): void {
        if(this._hitOneBtn.data.times == 0) {
            this._hitOneBtn.data.times = this._hitOneBtn.data.hitDelayTime;
            armyTemp.hit(this._hitOneBtn.data.hitBlood);
        }
    }
    private hitAll(): void {
        this.hitArmy(this._hitALLBtn.data.hitBlood);
    }
    private iceAll(): void {
        this.iceCount = this.enterFrameCount;
        this.hitArmy(this._iceBtn.data.hitBlood);
        for(var i in EnemyManage.i.armyList) {
            var armyTemp: ArmyBase = EnemyManage.i.armyList[i];
            armyTemp.data.iceCount = this._iceBtn.data.durationTime;
        }
    }
    private poisonAll(): void {

    }
    private god(): void {

    }
    private hitArmy(num: number): void {
        for(var i in EnemyManage.i.armyList) {
            var armyTemp:ArmyBase = EnemyManage.i.armyList[i];
            armyTemp.hit(num);
        }
    }

    private addEvent(): void {
        this.objCon.addEventListener(egret.TouchEvent.TOUCH_TAP,this.TOUCH_TAP_Handle,this);
    }
    private removeEvent(): void {
        this.objCon.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.TOUCH_TAP_Handle,this);
    }
    public dispose(): void {
        this.removeEvent();
    }
}





